class_name Trail
extends Line2D

@export var player: Player
@export var trail_duration := 1.0
@export var trail_length := 25

@onready var trail_timer: Timer = %TrailTimer

var is_active := false
var points_array: Array[Vector2] = []

func _process(_delta: float) -> void:
	if not is_active:
		return
	points_array.append(player.global_position)
	if points_array.size() > trail_length:
		points_array.pop_front()
		
	points = points_array
	
	
func start_trail() -> void:
	is_active = true
	remove_points()
	trail_timer.start(trail_duration)

func remove_points() -> void:
	points_array.clear()
	clear_points()


func _on_trail_timer_timeout() -> void:
	is_active = false
	remove_points()
